﻿//小区状况通用下拉框的获取
var uri = document.location.search;//接收页面传值
var i = uri.lastIndexOf("?") + 1;//获取问号前面的值
var P_ReportNumber = uri.substr(i);//截取问号前面的值
$(function () {
    ///判断状态去取消按钮
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Personal/selectbyP_ReportNumberss",
        data: {
            P_ReportNumber: P_ReportNumber
        },
        async: false,
        //contentType: 'application/json',
        success: function (data, status) {
            if (status == "success") {
                if (data != null) {
                    if (data.T_State != 1) {
                        $("#jbSub").remove();
                    }

                }
            }
        }
    })
    //下拉框数据加载
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Dictionary/GetDictionaryList",
        data: {
            Dmenuid: [7, 8, 9, 10, 11, 12, 13, 41]
        },
        async: false,
        success: function (data, status) {
            if (status == "success") {
                $("option").remove();
                $(data).each(function (i, obj) {
                    $(obj).each(function (j, item) {
                        switch (item.Dmenuid) {                         
                            case 7:
                                $("#T_CloseID").append("<option  value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 8:
                                $("#T_BuildingID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 9:
                                $("#T_TrafficZuzhiID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 10:
                                $("#T_AfforestID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 11:
                                $("#T_VolumeID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 12:
                                $("#T_StallID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                   break;
                            case 13:
                                $("#T_PropertyID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 41:
                                $("#T_SourceID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                        }
                    })
                })
            }
        }
    })
    //数据回填
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Community/SelectByid",
        data: {
            P_ReportNumber: P_ReportNumber
        },
        async: false,
        success: function (data, status) {
            if (status == "success") {
                if (data != null) {
                    $("#T_ReportNumber").val(data.T_ReportNumber)
                    $("#T_Project").val(data.T_Project)
                    $("#T_SourceID").val(data.T_SourceID)
                    $("#T_CloseID").val(data.T_CloseID)
                    $("#T_BuildingID").val(data.T_BuildingID)
                    $("#T_TrafficZuzhiID").val(data.T_TrafficZuzhiID)
                    $("#T_AfforestID").val(data.T_AfforestID)
                    $("#T_VolumeID").val(data.T_VolumeID)
                    $("#T_StallID").val(data.T_StallID)
                    $("#T_PropertyID").val(data.T_PropertyID)
                    $("#T_Else").val(data.T_Else)
                }
            }
        }
    })
})
//小区状况的数据添加
function insertCommunity() {
    var T_Project = $("#T_Project").val();                   // --项目案名   
    var T_SourceID = $("#T_SourceID option:checked").attr("value");     // --来源编号
   // var C_source = $("#C_source").val()                      //--来源情况编写
    var T_CloseID = $("#T_CloseID option:checked").attr("value");       //-小区封闭性编号
    var T_BuildingID = $("#T_BuildingID option:checked").attr("value"); //居住小区楼宇构成编号
    var T_TrafficZuzhiID = $("#T_TrafficZuzhiID option:checked").attr("value");   //交通组织方式编号
    var T_AfforestID = $("#T_AfforestID option:checked").attr("value"); //景观及绿化编号
    var T_VolumeID = $("#T_VolumeID option:checked").attr("value");     //容积率编号
    var T_StallID = $("#T_StallID option:checked").attr("value");       //车位编号
    var T_PropertyID = $("#T_PropertyID option:checked").attr("value")  //-物业公司编号
    var T_Else = $("#T_Else").val();		                 //其他


    var parms = {
        T_Project: T_Project,        // --项目案名   
        T_SourceID: T_SourceID,      // --来源编号
       // C_source: C_source,          //--来源情况编写
        T_CloseID: T_CloseID,        //-小区封闭性编号
        T_BuildingID: T_BuildingID,  //居住小区楼宇构成编号
        T_TrafficZuzhiID: T_TrafficZuzhiID,    //交通组织方式编号
        T_AfforestID: T_AfforestID,  //景观及绿化编号
        T_VolumeID: T_VolumeID,      //容积率编号
        T_StallID: T_StallID,        //车位编号
        T_PropertyID: T_PropertyID,  //-物业公司编号
        T_Else: T_Else,            //其他
        T_ReportNumber: P_ReportNumber  //报告号
    }
    $.ajax({
        type: "post",
        url: ApiUrl + "api/Community/Postinsert",
        data: parms,
        //contentType: 'application/json',
        success: function (data, status) {
            if (status == "success") {
                if (data == true) {
                    layer.msg('保存成功!', { icon: 1, time: 1000 });
                }
                else {
                    layer.msg('保存失败!', { icon: 2, time: 1000 });
                }
            }
        }
    })
}
